/*
 * Copyright 2008 CSC Consulting Group under the Apache License, 
 * Version 2.0 (the "License"); you may not use this file except in 
 * compliance with the License. You may obtain a copy of the License at 
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable 
 * law or agreed to in writing, software distributed under the License is 
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 * either express or implied. See the License for the specific language 
 * governing permissions and limitations under the License.
 */
package com.waw.memberMap.plugin.action;

import com.waw.memberMap.plugin.PluginUtils;
import com.waw.memberMap.plugin.PortalUser;
import com.jivesoftware.community.action.CommunityAction;
import com.jivesoftware.base.Log;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * This action class supports the presentation of a Community's members.
 * Member are users in groups whose names start with the display name of the community.
 * 
 */
public class MemberMapCommunityAction extends CommunityAction {

	private static final long serialVersionUID = 1L;
       
    /**
     * Returns the members in the community. 
     * @see  com.waw.memberMap.plugin.PortalUser
     * @see com.waw.memberMap.plugin.PluginUtils#getAllMembers(com.jivesoftware.community.Community)
     * @return iterator of PortalUser.
     */
    public Iterator<PortalUser>  getMembersInCommunity()
    {
    	List<PortalUser> allMembers = new ArrayList<PortalUser>();
		try {
			allMembers = PluginUtils.getAllMembers(this.getCommunity());
			Collections.sort(allMembers);
		} catch (Exception e) {
			Log.error("Problem retrieving community",e);
		}
    	return  allMembers.iterator();
    }


    /**
     * Always returns SUCCESS.
     * @see com.jivesoftware.community.action.CommunityAction#execute()
     */
    public String execute() {
    	super.execute();
    	return SUCCESS;
    }  
}